package com.example.xposeddemo;

import android.content.Context;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;


public class Tutorial2 implements IXposedHookLoadPackage {
    public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
        XposedHelpers.findAndHookMethod("com.SecShell.SecShell.AW", lpparam.classLoader,"attachBaseContext", Context.class, new XC_MethodHook() {
            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                //获取到Context对象，通过这个对象来获取classloader
                Context context = (Context) param.args[0];
                //获取classloader，之后hook加固后的就使用这个classloader
                ClassLoader classLoader = context.getClassLoader();
                //下面就是强classloader修改成壳的classloader就可以成功的hook了
                XposedHelpers.findAndHookMethod("com.linkage.mobile72.shanxi.utils.CheckUtil", classLoader, "checkRoot", new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        XposedBridge.log("成功hook到了checkRoot");
                    }
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        XposedBridge.log("把checkRoot的返回值改为了false");
                        param.setResult(false);
                    }
                });
            }
        });

    }
}

